(function($) {
	function crateCommentInfo(obj) {
		if(typeof(obj.time) == "undefined" || obj.time == ""){
			obj.time = getNowDateFormat();
		}
		var el = "<div class='comment-info'><div class='comment-right'><span class='comment-right-name'>"
				+ obj.replyName
				+ "</span>"
				+ "<div class='comment-content-header'><span><i class='glyphicon glyphicon-time'></i>"
				+ obj.time
				+ "</span></div><p class='content'>"
				+ obj.content
				+ "</p><div class='comment-content-footer'><div class='row'><div class='col-md-10'></div></div></div><div class='reply-list'>";// <div class='col-md-2'><span class='reply-btn'>回复</span></div>
		el = el + "</div></div></div>";
		return el;
	}
	
	function getNowDateFormat(){
		var nowDate = new Date();
		var year = nowDate.getFullYear();
		var month = filterNum(nowDate.getMonth()+1);
		var day = filterNum(nowDate.getDate());
		var hours = filterNum(nowDate.getHours());
		var min = filterNum(nowDate.getMinutes());
		var seconds = filterNum(nowDate.getSeconds());
		return year+"-"+month+"-"+day+" "+hours+":"+min+":"+seconds;
	}
	
	function filterNum(num){
		if(num < 10){
			return "0"+num;
		}else{
			return num;
		}
	}
	
	$.fn.addCommentList = function(options) {
		var defaults = {
			data : [],
			add : ""
		}
		var option = $.extend(defaults, options);
		// 加载数据
		if (option.data.length > 0) {
			var dataList = option.data;
			var totalString = "";
			for (var i = 0; i < dataList.length; i++) {
				var obj = dataList[i];
				var objString = crateCommentInfo(obj);
				totalString = totalString + objString;
			}
			$(this).append(totalString);
		}
		// 添加新数据
		if (option.add != "") {
			obj = option.add;
			var str = crateCommentInfo(obj);
			$(this).prepend(str)
		}
	}
})(jQuery);